package com.kuang.function;

import org.junit.Test;

import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

/**
 * @author luomingliang
 * @date 2021/5/25 20:58
 */
public class Demo1 {

    //Consumer 消费型
    @Test
    public void test001() {
//        Consumer<String> consumer = new Consumer<String>() {
//            @Override
//            public void accept(String s) {
//                System.out.println(s);
//            }
//        };
        Consumer<String> consumer = System.out::println;
        consumer.accept("hello");
    }

    //Supplier 供给型
    @Test
    public void test002() {
//        Supplier<String> supplier = new Supplier<String>() {
//            @Override
//            public String get() {
//                return "hello";
//            }
//        };
        Supplier<String> supplier = () -> "hello";
        System.out.println(supplier.get());
    }

    //Function 函数型
    @Test
    public void test003() {
        Function<String, String> function = x -> x;
        System.out.println(function.apply("hello"));
    }

    //Predicate 断定型
    @Test
    public void test004() {
        Predicate<String> predicate = x -> x.length()>0;
        System.out.println(predicate.test("hello"));
    }
}
